<template>
	<view class="box">
		<view class="plr20 pt20 pb240">
			<view class="boxItem mb20" v-if="objList.fmCode">
				<view class="flex mb20">
					<view class="name w160">设备名：</view>
					<view class="value">{{objList.fmName}}</view>
				</view>
				<view class="flex mb20">
					<view class="name w160">设备编号：</view>
					<view class="value">{{objList.fmCode}}</view>
				</view>
				<view class="flex mb20">
					<view class="name w160">设备型号：</view>
					<view class="value">{{objList.fmModel}}</view>
				</view>
				<view class="flex mb20">
					<view class="name w160">状态：</view>
					<view class="value">{{objList.fmStatusDesc}}</view>
				</view>
				<view class="flex mb20">
					<view class="name w160">使用部门：</view>
					<view class="value">{{objList.unitName + objList.depName}}</view>
				</view>
				<view class="flex mb20">
					<view class="name">设备使用地点：</view>
					<view class="value">{{objList.location}}</view>
				</view>
				<view class="flex mb20">
					<view class="name">上次维保时间：</view>
					<view class="value">{{objList.lastInspectionMaintenanceDate}}</view>
				</view>
			</view>
			<view class="boxItem mb20" v-if="objList.optionsList[0]">
				<view class="mb30 flex flex-center flex-itemCenter">
					<image src="../../static/iconListingScreening.png" class="wh40"></image>
					<text class="ml10" style="color: #414A53;">排查清单</text>
				</view>
				<view class="mb20" v-for="item in objList.optionsList" :key='item.id'>
					<view class="value">{{item.checkTitle}}</view>
					<u-radio-group v-model="item.result" placement="column">
						<view class="flex flex-end mt20 mb50">
							<view v-for="(item, index) in radiolist1" :key="index" class="ml30">
								<u-radio :customStyle="{marginBottom: '8px'}" :label="item.name" :name="item.disabled"
									labelSize="28rpx" size="15">
								</u-radio>
							</view>
						</view>
					</u-radio-group>
				</view>
			</view>
			<view class="boxItem mb20">
				<view class="mb20">备注</view>
				<u--textarea v-model="noExceptionList.remark"></u--textarea>
				<view class="mb20">附件</view>
				<view class="cont">
					<view class="cob" @click="checkAttac(noExceptionList.id)">查看相关附件</view>
					<view class="content-item-right">
						<files-upload @file="onUpload"></files-upload>
					</view>
				</view>
			</view>
		</view>
		<view class="maintenance">
			<view>
				<image src="../../static/iconAbnormalities.png" @click="navTo('addHiddenDanger')"></image>
				<view>异常</view>
			</view>
			<view>
				<image src="../../static/iconNoAbnormalities.png" @click="navTo('noAbnormalities')"></image>
				<view>无异常</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				radiolist1: [{
						name: '合格',
						disabled: true
					},
					{
						name: '不合格',
						disabled: false
					},
				],
				objList: {},
				noExceptionList: {
					id: '',
					fmQrCode: '',
					remark: '',
					annex: '',
					result: true,
					optionsList: []
				}
			}
		},
		onLoad(e) {
			if (e.resultValue) {
				this.objList = JSON.parse(e.resultValue)
				console.log(123, this.objList)
			}
			if (e.fmQrCode) {
				this.noExceptionList.fmQrCode = e.fmQrCode
			}
		},
		methods: {
			//页面跳转
			async navTo(e) {
				if(!this.objList.optionsList[0]){
					uni.showToast({
						icon:'none',
						title: "没有排查清单，请登录后台添加"
					})
					return
				}
				if (e == 'noAbnormalities') { //无异常
					let flag = true
					this.objList.optionsList.forEach((item) => { //循环判断是否全部合格
						if (!item.result) flag = false
					})
					if (flag) {
						if (this.noExceptionList.remark == '') {
							uni.showToast({
								icon:'none',
								title: "未填写备注信息"
							})
						} else {
							this.noExceptionList.optionsList = this.objList.optionsList
							// console.log(this.noExceptionList)
							let res = await this.request(this.$api.saveFmHiddenDangerCheck, this.noExceptionList,
								'POST')
							if (res.code == 200) {
								uni.redirectTo({
									url: './' + e + '?fmQrCode=' + this.noExceptionList.fmQrCode
								})
							}
						}

					} else {
						uni.showToast({
							icon:'none',
							title: "有不合格信息，请重新勾选"
						})
					}

				} else {
					if (this.noExceptionList.remark == '') {
						uni.showToast({
							icon:'none',
							title: "未填写备注信息"
						})
					} else {
						let flag = false
						this.objList.optionsList.forEach((item) => { //循环判断是否全部合格
							if (!item.result) flag = true
						})
						if(flag){
							this.noExceptionList.optionsList = this.objList.optionsList
							uni.redirectTo({
								url: './' + e + '?noExceptionList=' + JSON.stringify(this.noExceptionList)
							})
						}else{
							uni.showToast({
								icon:'none',
								title: "勾选项全部合格，无法提交异常"
							})
						}
					}
				}
			},
			//预览
			async pdf() {
				let res = await this.request(this.$api.getDownloadUrl, this.data1, 'POST')
				uni.downloadFile({
					url: res.resultValue,
					success: function(res) {
						var filePath = res.tempFilePath;
						uni.openDocument({
							filePath: filePath,
							showMenu: true,
							success: function(res) {
								console.log('打开文档成功');
							},
							fail: function(error) {
								console.log("打开本地文件失败")
							}
						});
					}
				});
			},
			//上传
			onUpload(e) {
				console.log(e)
				this.noExceptionList.id = e.uuid
				this.noExceptionList.annex = e.fileName
			},
			//预览
			checkAttac(id) {
				uni.navigateTo({
					url: './../checkTheAttachment/checkTheAttachment?classify=0503&connectId=' + id
				})
			}

		}
	}
</script>

<style scoped>
	.box {
		min-height: 100vh;
		background-color: #F1F2F5;
	}

	.w160 {
		width: 160rpx;
	}

	.maintenance {
		background-color: #FFFFFF;
		position: fixed;
		bottom: 0;
		height: 228rpx;
		width: 100%;
		box-shadow: 0 -1px 11px 0 rgba(0, 0, 0, 0.09);
		text-align: center;
		padding: 40rpx;
		box-sizing: border-box;
		display: flex;
		justify-content: space-around;
	}

	.maintenance image {
		width: 84rpx;
		height: 84rpx;
	}

	.maintenance view {
		font-family: PingFangSC-Regular;
		font-weight: Regular;
		font-size: 28rpx;
		color: #65717D;
	}

	.boxItem {
		padding: 30rpx;
		background-color: #fff;
		box-shadow: 0 2px 4px 0 rgba(237, 237, 237, 0.50);
		border-radius: 16rpx;
		position: relative;
	}

	.name {
		font-size: 28rpx;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: #89939E;
		padding-right: 20rpx;
	}

	.value {
		flex: 1;
		font-size: 28rpx;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: #333333;
	}

	.cob {
		flex: 1;
		font-size: 28rpx;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: #3473F9;
	}

	>>>.u-textarea {
		margin-bottom: 40rpx;
		background-color: #F5F6F9 !important;
		border: none;
	}
</style>
